package com.cloud.advice.util;


import com.cloud.advice.domain.response.ResponseResult;

public class ResponseUtil {
    private volatile static ResponseResult defaultValue = null;

    /**
     * 懒加载默认返回值
     *
     * @return
     */
    public static ResponseResult DefaultSuccessResult() {
        if (null == defaultValue) {
            synchronized (ResponseUtil.class) {
                if (defaultValue == null) {
                    defaultValue = new ResponseResult();
                    defaultValue.setCode(200);
                    defaultValue.setMsg("success");
                }
            }
        }
        return defaultValue;
    }

    public static ResponseResult build(int code, String msg, Object data) {
        ResponseResult result = new ResponseResult();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static ResponseResult buildExceptionResponse(int errorCode, String localizedMessage) {
        ResponseResult result = new ResponseResult();
        result.setCode(errorCode);
        result.setMsg("error");
        result.setData(localizedMessage);
        return result;
    }
}
